import request from './request.js'

// API基础URL
const BASE_URL = 'http://localhost:8080/api'

// 创建API请求函数
const createAPI = (url, method = 'GET') => {
	return (data) => request({
		url: BASE_URL + url,
		method,
		data
	})
}

export default {
	// 认证相关
	login: createAPI('/auth/login', 'POST'),
	register: createAPI('/auth/register', 'POST'),
	getUserInfo: createAPI('/auth/userinfo'),
	logout: createAPI('/auth/logout', 'POST'),
	
	// 订单相关
	getOrderList: (params) => request({
		url: `${BASE_URL}/order/list`,
		method: 'GET',
		data: params
	}),
	getOrderDetail: (id) => request({
		url: `${BASE_URL}/order/${id}`,
		method: 'GET'
	}),
	createOrder: createAPI('/order/create', 'POST'),
	acceptOrder: (id) => request({
		url: `${BASE_URL}/order/${id}/accept`,
		method: 'POST'
	}),
	assignOrder: (id, data) => request({
		url: `${BASE_URL}/order/${id}/assign`,
		method: 'POST',
		data
	}),
	completeOrder: (id) => request({
		url: `${BASE_URL}/order/${id}/complete`,
		method: 'POST'
	}),
	cancelOrder: (id) => request({
		url: `${BASE_URL}/order/${id}/cancel`,
		method: 'POST'
	}),
	
	// 分类相关
	getCategoryList: createAPI('/category/list'),
	getCategoryDetail: (id) => request({
		url: `${BASE_URL}/category/${id}`,
		method: 'GET'
	}),
	
	// 用户相关
	getUserStats: createAPI('/user/stats'),
	getTechList: createAPI('/user/tech-list'),
	updateUserInfo: createAPI('/user/update', 'POST'),
	getUserList: (params) => request({
		url: `${BASE_URL}/user/list`,
		method: 'GET',
		data: params
	}),
	updateUserStatus: (id, status) => request({
		url: `${BASE_URL}/user/${id}/status`,
		method: 'PUT',
		data: { status }
	}),
	getProfile: createAPI('/user/profile'),
	updateProfile: createAPI('/user/profile', 'PUT'),
	
	// 结算相关
	getSettlementList: (params) => request({
		url: `${BASE_URL}/settlement/list`,
		method: 'GET',
		data: params
	}),
	settleOrder: (id) => request({
		url: `${BASE_URL}/settlement/${id}/settle`,
		method: 'POST'
	}),
	
	// 订单进度相关
	getOrderProgress: (orderId) => request({
		url: `${BASE_URL}/order-progress/list/${orderId}`,
		method: 'GET'
	}),
	addOrderProgress: createAPI('/order-progress/add', 'POST'),
	
	// 统计数据相关
	getDashboardStats: createAPI('/dashboard/stats'),
	getTechDashboardStats: createAPI('/dashboard/tech-stats'),
	getDispatcherDashboardStats: createAPI('/dashboard/dispatcher-stats'),
	
	// 派单相关
	getAvailableTechs: createAPI('/dispatcher/available-techs'),
	assignOrderToTech: (orderId, techId) => request({
		url: `${BASE_URL}/dispatcher/order/${orderId}/assign/${techId}`,
		method: 'POST'
	}),
	
	// 技术员相关
	getTechOrders: (params) => request({
		url: `${BASE_URL}/tech/orders`,
		method: 'GET',
		data: params
	}),
	getTechEarnings: (params) => request({
		url: `${BASE_URL}/tech/earnings`,
		method: 'GET',
		data: params
	}),
	
	// 快速登录
	quickLogin: createAPI('/auth/quick-login', 'POST')
}